package com.qinker.robot.hook.aio;

import com.alibaba.fastjson.JSONObject;
import com.qinker.robot.common.RobotConstants;
import com.qinker.robot.hook.aio.receive.RobotRecipient;
import com.qinker.robot.common.model.PrivateChatRequest;
import com.sky.xposed.common.util.Alog;

import org.smartboot.ioc.MessageProcessor;
import org.smartboot.ioc.StateMachineEnum;
import org.smartboot.ioc.transport.NioSession;

/**
 * Created by Irany 2019/10/27 0027 10:48
 */
public class ClientProcessor implements MessageProcessor<String> {

    private RobotRecipient robotRecipient = new RobotRecipient();

    @Override
    public void process(NioSession<String> session, String msg) {
        JSONObject jsonObject = JSONObject.parseObject(msg);
        Alog.d("client收到消息: " + msg);
        if (RobotConstants.Handle.HANDLE_PRIVATE_CHAT.equals(jsonObject.getString("opcode"))) {
            robotRecipient.chat(jsonObject.toJavaObject(PrivateChatRequest.class));
        } else if (RobotConstants.Handle.HANDLE_PRIVATE_CHAT_MASS.equals(jsonObject.getString("opcode"))) {
            robotRecipient.chatMass(jsonObject.toJavaObject(PrivateChatRequest.class));
        }
    }

    @Override
    public void stateEvent(NioSession<String> session, StateMachineEnum stateMachineEnum, Throwable throwable) {

    }
}